﻿            $('.form1').validate({
                debug: true,
                onfocusout: function (element, event) {
                    $(element).valid();
                },
                focusInvalid: true,
                highlight: function (element, errorClass) {
                    $(element).addClass('alert');
                },
                unhighlight: function (element, errorClass) {
                    $(element).removeClass('alert');
                }
            });

            $.validator.addMethod("regex", function (value, element, regexp) {
                if ($(element).hasClass('Red-Required')) {
                    return (new RegExp(regexp)).test(value) && $(element).val().length > 0;
                }
                else
                    return (new RegExp(regexp)).test(value) || $(element).val().length == 0;
            }, '');

            $.each($('.container .Red-Required'), function (i, n) { //中文字符
                $(n).rules('add', {
                    required: true,
                    regex: /./,
                    messages: {}
                });
            });
            $.each($('.container .Chin-Check'), function (i, n) { //中文字符
                $(n).rules('add', {
                    required: true,
                    regex: /^[\u4e00-\u9fa5]{1,4}$/,
                    messages: {}
                });
            });
            $.each($('.container .Double-Check'), function (i, n) {//浮点字符
                $(n).rules('add', {
                    regex: /^([+-]?(((\d+(\.)?)|(\d*\.\d+))([eE][+-]?\d+)?))$/,
                    messages: {}
                });
            });
            $.each($('.container .Eng-Check'), function (i, n) {//小写字母字符
                $(n).rules('add', {
                    required: true,
                    regex: /^[a-z]+$/,
                    messages: {}
                });
            });
            $.validator.messages.required = '';

///他的validate是通过name来进行的, 如果name重复, 只会处理第一个, 修改源文件里的checkForm方法可以修改这个问题
            //this.prepareForm();
            //for (var i = 0, elements = (this.currentElements = this.elements()); elements[i]; i++) {
            //    if (this.findByName(elements[i].name).length != undefined && this.findByName(elements[i].name).length > 1) {
            //        for (var cnt = 0; cnt < this.findByName(elements[i].name).length; cnt++) {
            //            this.check(this.findByName(elements[i].name)[cnt]);
            //        }
            //    } else {
            //        this.check(elements[i]);
            //    }
            //}
            //return this.valid();